/*
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef CAMERA_SAMPLE_H
#define CAMERA_SAMPLE_H

using namespace std;
using namespace OHOS;
using namespace OHOS::Media;

#include "camera_kit.h"
#include "recorder.h"
#include "camera_sample.h"

class SampleFrameStateCallback : public FrameStateCallback {
    void OnFrameFinished(Camera &camera, FrameConfig &fc, FrameResult &result) override;
};

class SampleCameraDeviceCallback : public CameraDeviceCallback {
};

class SampleCameraStateMng : public CameraStateCallback {
public:
	~SampleCameraStateMng();
    SampleCameraStateMng() = delete;
    SampleCameraStateMng(EventHandler &eventHdlr) : eventHdlr_(eventHdlr) {}
    void OnCreated(Camera &c)override;
    void OnCreateFailed(const std::string cameraId, int32_t errorCode)override;
    void OnReleased(Camera &c)override;
    void CloseRecorder(void);
    int PrepareRecorder(void);
    void StartRecord(void);
    void StartPreview(void);
    void Capture(void);
    void Stop(void);
    Recorder *recorder_ = nullptr;
private:
    enum State : int32_t { STATE_IDLE, STATE_RUNNING, STATE_BUTT };
    State previewState_ = STATE_IDLE;
    State recordState_ = STATE_IDLE;
    EventHandler &eventHdlr_;
    Camera *cam_ = nullptr;
    int32_t recordFd_ = -1;
    SampleFrameStateCallback fsCb_;
};

#endif

